//
//  ContentModeViewController.m
//  TotalDemo
//
//  Created by gujian on 16/5/26.
//  Copyright © 2016年 gujian. All rights reserved.
//

#import "ContentModeViewController.h"

@interface ContentModeViewController ()

@end

@implementation ContentModeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self setupSubViews];
    
}

- (void)setupSubViews
{
    //480 * 150
    CGFloat imgWidth = SCREEN_WIDTH;
    CGFloat imgHeight = 94;
    
    CGFloat offY = 10;
    
    NSArray *modeArr = @[@(UIViewContentModeScaleToFill),@(UIViewContentModeScaleAspectFit),@(UIViewContentModeScaleAspectFill)];
    
    for (int i = 0; i < 3; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, offY, imgWidth, imgHeight)];
        imageView.contentMode = [modeArr[i] integerValue];
        imageView.clipsToBounds = YES;
        imageView.image = [UIImage imageNamed:@"cat.jpg"];//banner
        imageView.backgroundColor = [UIColor randomColor];
        [self.view addSubview:imageView];
        offY += (imgHeight + 20);
    }
    
    
    /**
     *1. UIViewContentModeScaleToFill   （拉伸,铺满父视图）
     *   图像的长和宽拉伸铺满视图
     *
     */
    
    /**
     *2. UIViewContentModeScaleAspectFit   （等比缩放）
     *   假设原始图像宽、高为 imgW和imgH
     *   UIImageView的宽高为   W和H
     *   渲染图像宽高为 renderW和renderH
     *   ratioW = imgW / W;     rationH = imgH / H;
     *   renderW = Min(rationW,rationH) * imgW;
     *   renderH = Min(rationW,rationH) * imgH;
     */
    
    
    /**拉伸
     *3. UIViewContentModeScaleAspectFill   （拉伸，等比缩放）
     *   先铺满父视图的长或宽的一边，然后等比缩放另一边
     *   假设原始图像宽、高为 imgW和imgH
     *   UIImageView的宽高为   W和H
     *   渲染图像宽高为 renderW和renderH
     *   ratioW = imgW / W;     rationH = imgH / H;
     *   if（Max(rationW,rationH) == rationW）
     *   {
     *       rederW = rationW * imgW;
     *       renderH = H;
     *   }
     *
     *    else
     *   {
     *       renderH = rationH * imgH;
     *       renderW = W;
     *   }
     *
     */
    
}

@end
